﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;

    public class SkuClass : BasePage
    {
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected CheckBox chkIsActive;
        protected HtmlForm F2091;
        protected HtmlInputHidden hdnFrom;
        protected HtmlImage imgOwnerID;
        protected Label lblDescr;
        protected Label lblDescr2;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblOwnerID;
        protected Label lblSkuClassID;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf4;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUdf9;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        protected TextBox txtDescr;
        protected TextBox txtDescr2;
        protected TextBox txtOwnerID;
        protected TextBox txtSkuClass;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;
        protected UpdatePanel up1;

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtSkuClass.Text = "";
            this.txtOwnerID.Text = "";
            this.txtSkuClass.Enabled = true;
            this.txtOwnerID.Enabled = true;
            base.DataEntityViewState = null;
            this.imgOwnerID.Visible = true;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtSkuClass.Text.Trim()) && !string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                try
                {
                    List<string> skuClassID = new List<string> {
                        this.txtSkuClass.Text.Trim()
                    };
                    List<string> OwnerID = new List<string> {
                        this.txtOwnerID.Text.Trim()
                    };
                    List<string> pk3 = new List<string>();
                    this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().DeleteDetail(skuClassID, OwnerID, pk3, "SKU_CLASS") + base.GetGlobalMsgResource("C006");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                    base.DataEntityViewState = null;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("SkuClassQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("SkuClassList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtSkuClass.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_015");
            }
            else if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_001");
            }
            else if (base.DataEntityViewState != null)
            {
                this.UpdateSkuClassInfo();
            }
            else
            {
                this.InsertSkuClassInfo();
            }
        }

        private void InsertSkuClassInfo()
        {
            try
            {
                SkuClassInfo skuClass = new SkuClassInfo {
                    SkuClassID = this.txtSkuClass.Text.Trim(),
                    OwnerID = this.txtOwnerID.Text.Trim(),
                    Descr = this.txtDescr.Text.Trim(),
                    Descr2 = this.txtDescr2.Text.Trim(),
                    IsActive = this.chkIsActive.Checked ? "Y" : "N",
                    CreatedBy = base.UserInfo.UserID,
                    Udf1 = this.txtUdf1.Text.Trim(),
                    Udf2 = this.txtUdf2.Text.Trim(),
                    Udf3 = this.txtUdf3.Text.Trim(),
                    Udf4 = this.txtUdf4.Text.Trim(),
                    Udf5 = this.txtUdf5.Text.Trim(),
                    Udf6 = this.txtUdf6.Text.Trim(),
                    Udf7 = this.txtUdf7.Text.Trim(),
                    Udf8 = this.txtUdf8.Text.Trim(),
                    Udf9 = this.txtUdf9.Text.Trim(),
                    Udf10 = this.txtUdf10.Text.Trim()
                };
                this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(skuClass, "SKU_CLASS") + base.GetGlobalMsgResource("C004");
                base.DataEntityViewState = skuClass;
                this.txtSkuClass.Enabled = false;
                this.txtOwnerID.Enabled = false;
                this.imgOwnerID.Visible = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        private void LoadData()
        {
            if (!(string.IsNullOrEmpty(base.Request.QueryString["ID"]) || string.IsNullOrEmpty(base.Request.QueryString["OwnerID"])))
            {
                this.SetSkuClassInfo2Form();
            }
            else
            {
                base.SetDefaultOwner(this.txtOwnerID);
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetSkuClassInfo2Form()
        {
            try
            {
                string skuClassID = base.Request.QueryString["ID"].ToString();
                string ownerID = base.Request.QueryString["OwnerID"].ToString();
                SkuClassInfo skuClass = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(skuClassID, ownerID, "", "SKU_CLASS") as SkuClassInfo;
                if (skuClass != null)
                {
                    base.DataEntityViewState = skuClass;
                    this.txtSkuClass.Text = skuClass.SkuClassID;
                    this.txtOwnerID.Text = skuClass.OwnerID;
                    this.txtOwnerID.Enabled = false;
                    this.imgOwnerID.Visible = false;
                    this.txtDescr.Text = skuClass.Descr;
                    this.txtDescr2.Text = skuClass.Descr2;
                    this.chkIsActive.Checked = skuClass.IsActive == "Y";
                    this.txtUdf1.Text = skuClass.Udf1;
                    this.txtUdf2.Text = skuClass.Udf2;
                    this.txtUdf3.Text = skuClass.Udf3;
                    this.txtUdf4.Text = skuClass.Udf4;
                    this.txtUdf5.Text = skuClass.Udf5;
                    this.txtUdf6.Text = skuClass.Udf6;
                    this.txtUdf7.Text = skuClass.Udf7;
                    this.txtUdf8.Text = skuClass.Udf8;
                    this.txtUdf9.Text = skuClass.Udf9;
                    this.txtUdf10.Text = skuClass.Udf10;
                    this.txtSkuClass.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void UpdateSkuClassInfo()
        {
            try
            {
                SkuClassInfo skuClass = base.DataEntityViewState as SkuClassInfo;
                skuClass.Descr = this.txtDescr.Text.Trim();
                skuClass.Descr2 = this.txtDescr2.Text.Trim();
                skuClass.IsActive = this.chkIsActive.Checked ? "Y" : "N";
                skuClass.UpdatedBy = base.UserInfo.UserID;
                skuClass.Udf1 = this.txtUdf1.Text.Trim();
                skuClass.Udf2 = this.txtUdf2.Text.Trim();
                skuClass.Udf3 = this.txtUdf3.Text.Trim();
                skuClass.Udf4 = this.txtUdf4.Text.Trim();
                skuClass.Udf5 = this.txtUdf5.Text.Trim();
                skuClass.Udf6 = this.txtUdf6.Text.Trim();
                skuClass.Udf7 = this.txtUdf7.Text.Trim();
                skuClass.Udf8 = this.txtUdf8.Text.Trim();
                skuClass.Udf9 = this.txtUdf9.Text.Trim();
                skuClass.Udf10 = this.txtUdf10.Text.Trim();
                this.lblMsg.Text = BaseInfoDetailServiceClientProxy.GetInstance().UpdateDetail(skuClass, "SKU_CLASS") + base.GetGlobalMsgResource("C002");
                this.imgOwnerID.Visible = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

